# -*- coding: utf-8 -*-#

# -------------------------------------------------------------------------------
# Name:         main
# Description:
# Author:       zx
# Date:         2020/9/28
# -------------------------------------------------------------------------------
import argparse

from concern.config import Config, Configurable


def main():
    parser = argparse.ArgumentParser(description='Text Recognition Training')
    parser.add_argument('--exp', type=str, default="experiments/seg_detector/base_totaltext.yaml")
    args = parser.parse_args()
    args = vars(args)
    args = {k: v for k, v in args.items() if v is not None}
    conf = Config()
    # experiment_args = conf.compile(conf.load(args['exp']))['train_data']
    experiment_args = conf.compile(conf.load(args['exp']))['validate_data']
    experiment_args.update(cmd=args)
    train_data_loader = Configurable.construct_class_from_config(experiment_args)
    return train_data_loader


if __name__ == '__main__':
    import numpy as np

    for i in range(100):
        image_dict, image_label = main().__getitem__(i)
        print(image_dict.keys())
        print(np.array(image_label).shape)
        import cv2

        # print(image_dict["image"].shape)
        # print(np.sum(np.array(image_dict["image"]) < 0))
        # print(image_dict["polygons"])
        # print(image_dict["ignore_tags"])
        # print(image_dict["shape"])
        # print(image_dict["filename"])
        # print(image_dict["is_training"])

        print(image_dict["image"].shape)
        cv2.imshow("image", image_dict["image"] * 255)

        print(image_dict["gt"].shape)
        cv2.imshow("gt", image_dict["gt"] * 255)

        print(image_dict["mask"].shape)
        # print(image_dict["mask"])
        cv2.imshow("mask", image_dict["mask"])

        # print(image_dict["thresh_map"].shape)
        # cv2.imshow("thresh_map", image_dict["thresh_map"])
        #
        # print(image_dict["thresh_mask"].shape)
        # cv2.imshow("thresh_mask", image_dict["thresh_mask"])
        cv2.waitKey(0)
    # print(dict(main().__getitem__(1)))
    # print(image_dict["thresh_mask"].shape)
    # print(image_dict["mask"].shape)
    # print(main().__len__())
